package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.SetPspStatusBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.SetPspStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.List;
import java.util.Map;
/**
*运营端审核PSP商品的状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetPspStatus{
	private static SetPspStatusBean setpspstatusBean = new SetPspStatusBean();
	private static SetPspStatusCall setpspstatusCall = new SetPspStatusCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	private static Integer sellerId1 = Integer.valueOf(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("运营端审核PSP商品的状态");
	}

	@Before
	public void caseUp() {
		setpspstatusBean=new SetPspStatusBean();
		setpspstatusCall=new SetPspStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setpspstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetPspStatus_001() {
		Logger.start(true,"运营端审核PSP商品的状态——优选待审状态3,优选买手,通过巡检，不撤标");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addProdReq.getProduct().setCatalogStatus(3);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			new YmtProductsIWapper().updatePspStatus(productId, 3);
			
			setpspstatusBean.setIsPassViolate(true);
			setpspstatusBean.setIsRemovePsp(true);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(sellerId);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();	
			Logger.verifyEquals("200", setpspstatusCall.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			int i = 4;
			short j = (short)i;
			Logger.verifyEquals((short)4, pspStatus, "验证pspStatus");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetPspStatus_002() {
		Logger.start(true,"运营端审核PSP商品的状态——优选待审状态3，优选买手,没有通过巡检，撤标");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
			ymtProductsIWapper.updatePspStatus(productId,3);
			
			setpspstatusBean.setIsPassViolate(false);
			setpspstatusBean.setIsRemovePsp(false);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(sellerId);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();			
			Logger.verifyEquals("200", setpspstatusCall.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			Logger.verifyEquals((short)1, pspStatus, "验证pspStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetPspStatus_003() {
		Logger.start(true,"运营端审核PSP商品的状态——优选待审状态3，优选买手,通过巡检，撤标");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
			ymtProductsIWapper.updatePspStatus(productId,3);
			
			setpspstatusBean.setIsPassViolate(true);
			setpspstatusBean.setIsRemovePsp(false);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(sellerId);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();			
			Logger.verifyEquals("200", setpspstatusCall.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			Logger.verifyEquals((short)4, pspStatus, "验证pspStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetPspStatus_004() {
		Logger.start(true,"运营端审核PSP商品的状态——不是优选待审状态3，优选买手,通过巡检");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
			ymtProductsIWapper.updatePspStatus(productId,1);
			
			setpspstatusBean.setIsPassViolate(true);
			setpspstatusBean.setIsRemovePsp(false);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(sellerId);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();		
			//非审核中的商品，不能操作人工审核
			Logger.verifyEquals("201", setpspstatusCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	/**
	 * 不是优选买手不落库
	 */
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetPspStatus_005() {
		Logger.start(true,"运营端审核PSP商品的状态——优选待审状态3,不是优选买手,通过巡检，不撤标");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(288484);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//new YmtProductsIWapper().updatePspStatus(productId, 3);
			
			setpspstatusBean.setIsPassViolate(true);
			setpspstatusBean.setIsRemovePsp(true);
			setpspstatusBean.setProductId(productId);
			setpspstatusBean.setSellerId(20345997);
			setpspstatusCall.setData(setpspstatusBean);
			setpspstatusCall.callService();	
			Logger.verifyEquals("201", setpspstatusCall.getString("Code"), "验证Code");
			List<Map> selectPspStatus = new YmtProductsIWapper().selectPspStatus(productId, 20345997);
			Logger.verifyEquals(true, selectPspStatus.isEmpty(), "验证数据库为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}